/**
 * Created by zn on 17-4-5.
 */
'use strict';
import setting from '../setting'
var regular = {
    reg: {
        email: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
        password: /^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])|(?=.*[A-Z])(?=.*[a-z])(?=.*[^A-Za-z0-9])|(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9])|(?=.*[a-z])(?=.*[0-9])(?=.*[^A-Za-z0-9])).{6,}|(?:(?=.*[A-Z])(?=.*[a-z])|(?=.*[A-Z])(?=.*[0-9])|(?=.*[A-Z])(?=.*[^A-Za-z0-9])|(?=.*[a-z])(?=.*[0-9])|(?=.*[a-z])(?=.*[^A-Za-z0-9])|(?=.*[0-9])(?=.*[^A-Za-z0-9])|).{6,18}$/,
        captcha: /^\d{6}$/,
        token: /^[a-f0-9]{32}$/,
        uid: /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/
    },
    checkEmail: function(email){
        return email && this.reg.email.test(email)
    },
    checkPassword: function(pwd){
        return pwd && this.reg.password.test(pwd)
    },
    checkCaptcha: function(captcha){
        return captcha && this.reg.captcha.test(captcha)
    },
    checkPlatform: function(platform){
        return platform && setting.platform.indexOf(Number(platform)) >= 0
    },
    checkCaptchaType: function(type){
        return type && [1, 2].indexOf(Number(type)) >= 0
    },
    checkToken: function(token){
        return token && this.reg.token.test(token)
    },
    checkUID: function (uid){
        return uid && this.reg.uid.test(uid)
    }
}
module.exports = regular